﻿Imports System.Data
Imports System.Data.SqlClient
Partial Class listuser
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        If Not Page.IsPostBack Then
            BindGrid()
        End If
    End Sub
    Private Sub BindGrid()
        Dim records As Int16 = 5, totalRecords As Int16 = 0
        Dim strWhere As String = " where 1=1 "
        Label1.Text = ""
        If IsNumeric(Request.QueryString("id")) Then
            strWhere += " and iddonhang=" & Request.QueryString("id")
            Label1.Text = getUser(Request.QueryString("id"))
        End If
        Dim myConn As New SqlConnection(ConfigurationSettings.AppSettings("cons"))
        Dim sSql As String = "select * from vwctdonhang " & strWhere & " order by iddonhang desc"
        myConn.Open()
        Dim myAdapter As New SqlDataAdapter(sSql, myConn)
        Dim myDataSet As New DataSet
        myAdapter.Fill(myDataSet, sSql)
        totalRecords = myDataSet.Tables(sSql).Rows.Count
        DataGrid1.DataSource = myDataSet
        If totalRecords >= 2 * records Then
            DataGrid1.AllowPaging = True
            DataGrid1.PageSize = records
            DataGrid1.PagerStyle.Mode = PagerMode.NumericPages
            DataGrid1.PagerStyle.Font.Bold = True
            DataGrid1.PagerStyle.PageButtonCount = 5
            DataGrid1.PagerStyle.Position = PagerPosition.TopAndBottom
            DataGrid1.PagerStyle.HorizontalAlign = HorizontalAlign.Right
        Else
            DataGrid1.AllowPaging = False
        End If
        DataGrid1.DataBind()
        myConn.Close()
    End Sub
    Public Sub DataGrid1_PageIndexChanged(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
        DataGrid1.CurrentPageIndex = e.NewPageIndex
        BindGrid()
    End Sub
    Private Function getUser(ByVal vIdDonhang As Int16)
        Dim myConn As New SqlConnection(ConfigurationSettings.AppSettings("cons"))
        Dim sSql As String = "select top 1 kh.* from khachhang kh,donhang dh where kh.idkhachhang = dh.idkhachhang and dh.iddonhang=" & vIdDonhang
        myConn.Open()
        Dim myComm As New SqlCommand(sSql, myConn)
        Dim myDr As SqlDataReader
        Dim strNoidung As String = ""
        myDr = myComm.ExecuteReader
        If myDr.Read() Then
            strNoidung = "<h3> Thông tin khách hàng </h3>"
            strNoidung += "Họ tên : <b>" + myDr("hoten").ToString() + "</b><br>"
            strNoidung += "Điện thoại : " + myDr("dienthoai").ToString() + "<br>"
            strNoidung += "Email : " + myDr("email").ToString() + "<br>"
            strNoidung += "Địa chỉ : " + myDr("diachi").ToString() + "<br>"
            strNoidung += "Thành phố - Quốc gia : " + myDr("thanhpho").ToString() + " - " + myDr("quocgia").ToString() + "<br>"
            strNoidung += "<h3> Thông tin đặt hàng </h3>"
            myDr.Close()
        End If
        myConn.Close()
        Return strNoidung
    End Function
End Class
